package com.itheima.bos.web.action;

import com.itheima.bos.domain.Function;
import com.itheima.bos.service.IFunctionService;
import com.itheima.bos.utils.BOSContext;
import com.itheima.bos.web.action.base.BaseAction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import java.io.IOException;
import java.util.List;

/**
 * Created by Mr.King on 2017/3/16.
 */
@Controller
@Scope("prototype")
public class FunctionAction extends BaseAction<Function> {

    @Autowired
    private IFunctionService functionService;

    /**
     * 查询所有权限
     */
    public String findAll() throws IOException {
        List<Function> list = functionService.findAll();

        String[] arr = new String[]{"parentFunction", "children", "roles"};
        toJSON(list, arr);
        return NONE;
    }

    /**
     * 根据权限查询菜单数据
     */
    public String findMenu() throws IOException {
        List<Function> list = functionService.findMenu(BOSContext.getLoginUser());
        String[] arr = new String[]{"parentFunction", "children", "roles"};
        toJSON(list,arr);
        return NONE;
    }
}
